<template>
	<view class="assess_page">
		<!-- <view class="top_box">服务商品<span style="color: #666666;margin-left: 32rpx;">家居（衣柜）-安装</span></view> -->
		<view class="assess_box">
			<view class="item">
				<view>态度评分:</view>
				<u-rate :count="count" v-model="score_manner" activeColor="#FF7448" size="20"></u-rate>
			</view>
			<view class="item">
				<view>技能评分:</view>
				<u-rate :count="count" v-model="score_skill" activeColor="#FF7448" size="20"></u-rate>
			</view>
			<view class="item">
				<view>服务评分:</view>
				<u-rate :count="count" v-model="score_service" activeColor="#FF7448" size="20"></u-rate>
			</view>
			<view class="img_box">
				<view class="imgs">
					<u-upload uploadText="添加图片" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1"
						multiple :maxCount="5"></u-upload>
				</view>
				
				<textarea class="ipt" v-model="content" placeholder="请使用文字描述您的使用感受~"></textarea>
			</view>
		</view>
		<button class="sumbtn" @click="assess()">提交评价</button>
	</view>
</template>

<script>
	import {assessOrder} from "../../api/index.js"
	export default {
		data() {
			return {
				id:'',
				count:5,
				fileList1: [],
				score_skill:'',
				score_service:'',
				score_manner:'',
				content:'',
				images:[]
			}
		},
		onLoad(e) {
			this.id=e.id
		},
		methods: {
			assess(){
				let p = {
					order_id:this.id,
					content:this.content,
					images:this.images,
					score_skill:this.score_skill,
					score_service:this.score_service,
					score_manner:this.score_manner
				}
				assessOrder(p).then(res=>{
					uni.showToast({
						icon:'success',
						title:'评价成功'
					})
					setTimeout(()=>{
						uni.switchTab({
							url:"/pages/order/order"
						})
					},800)
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://xiaoan.lf520.vip/api/common/upload',
						filePath: url,
						name: 'file',
						header: {
							token: uni.getStorageSync('tokenVal')
						},
						formData: {
							user: 'test'
						},
						success: (res) => {
							let p=JSON.parse(res.data)
							this.images.push(p.data.fullurl)
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.assess_page{
	width: 100%;
	height: 100vh;
	background-color: #F9F9F9;
	.img_box{
		width: 100%;
		height: auto;
		min-height: 180rpx;
		// background-color: forestgreen;
		margin-top: 52rpx;
		.imgs{
			width: 100%;
			height: auto;
			min-height: 128rpx;
			display: flex;
		}
		.ipt{
			width: 686rpx;
			height: auto;
			min-height: 40rpx;
			white-space: nowrap;
			margin-top: 20rpx;
		}
	}
	
}
.top_box{
	width: 100%;
	height: 104rpx;
	padding: 32rpx;
	background-color: #FFFFFF;
	color: #333333;
	font-size: 28rpx;
	font-weight: bold;
}
.assess_box{
	width: 100%;
	height: auto;
	min-height: 472rpx;
	background-color: #FFFFFF;
	margin-top: 20rpx;
	padding: 32rpx;
	.item{
		display: flex;
		margin-bottom: 32rpx;
		view{
			height: 40rpx;
			line-height: 40rpx;
			color: #333333;
			font-size: 24rpx;
			font-weight: bold;
			margin-right: 16rpx;
		}
	}
}
.sumbtn{
	width: 686rpx;
	height: 88rpx;
	background-color: #00CC7B;
	color: #FFFFFF;
	font-size: 32rpx;
	margin: auto;
	margin-top: 96rpx;
	border-radius: 128rpx;
}
</style>
